import pandas as pd
from selenium import webdriver
import numpy as np
import re
import time
import os


option = webdriver.ChromeOptions()
option.add_argument('headless')
open_driver = webdriver.Chrome()
# open_driver = webdriver.Firefox()
# open_driver = webdriver.PhantomJS()
open_driver.get('https://www.wanplus.com/lol/teamstats')
content1 = open_driver.find_element_by_xpath('//*[@id="DataTables_Table_0"]/tbody')
data1 = content1.text
data1 = data1.split()


nextPage = open_driver.find_element_by_xpath('/html/body/div/div[2]/div[3]/div[1]')
nextPage.click()
time.sleep(5)
content2 = open_driver.find_element_by_xpath('//*[@id="DataTables_Table_0"]/tbody')

data2 = content2.text
data2 = data2.split()

a = np.array(data1)
a = a.reshape(16,-1)
b = np.array(data2)
b = b.reshape(16,-1)

np.save('1',a)
np.save('2',b)


open_driver.close()

index_a = ['名次','战队','KDA',	'场均击杀','场均死亡','每分钟伤害',	'一血率',	'场均时长',	'场均经济',	'每分钟经济',	'每分钟补刀']

index_b = ['名次','战队', 	'场均小龙',	'小龙控制率',	'场均大龙',	'大龙控制率',	'每分钟插眼',	'每分钟排眼'	,'排眼效率',	'场均推塔数'	,'场均被推塔数']

dataframe_a = pd.DataFrame(a,columns=index_a)
dataframe_b = pd.DataFrame(b,columns=index_b)

dataframe_a.to_csv('attack.csv',index=False)
dataframe_b.to_csv('resource.csv',index=False)